package com.internetCafes.spms.web.extend.model;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.internetCafes.spms.core.utils.DateUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * <p>
 * 
 * </p>
 *
 * @author LinYe
 * @since 2020-12-08
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("x_ent_certi_iso")
public class EntCertiIso implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id",type = IdType.AUTO)
    private Long id;

    /**
     * 企业id,引用t_tenant_info表
     */
    private Long tenantId;

    /**
     * 证书名称
     */
    private String name;

    /**
     * 证书编号
     */
    private String code;

    /**
     * 发证日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date releaseDate;

    /**
     * 到期日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date expireDate;

    /**
     * 1长期有效,0非长期有效
     */
    private Integer longTerm;

    /**
     * 发证机构
     */
    private String releaseOrgan;

    /**
     * 证书覆盖范围
     */
    private String coverage;

    /**
     * 认证机构
     */
    private String authOrgan;

    /**
     * 认证标准
     */
    private String authStandards;

    /**
     * 初审费用
     */
    private Double firstAuditFee;

    /**
     * 保管人id,引用t_employee_info表
     */
    private Long keepEmployeeId;

    /**
     * 备注
     */
    private String remark;

    /**
     * 状态：-1作废,0空闲
     */
    private Integer status;

    /**
     * 作废备注
     */
    private String unableRemark;

    /**
     * 创建者,引用t_employee_info表
     */
    @TableField(fill = FieldFill.INSERT)
    private Long createBy;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createTime;

    /**
     * 更新人,引用t_employee_info表
     */
    @TableField(fill = FieldFill.UPDATE)
    private Long updateBy;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @TableField(fill = FieldFill.UPDATE)
    private Date updateTime;

    public Integer getWarningCount(){
        if(this.getExpireDate() == null){
            return null;
        }
        return (int) ((this.getExpireDate().getTime() - System.currentTimeMillis()) / (1000*3600*24)) ;
    }

    public boolean getWarning(){
        if(this.getExpireDate() == null){
            return false;
        }
        return this.getExpireDate().getTime() > new Date().getTime() && this.getExpireDate().getTime() < DateUtils.getBeAfMonth(3).getTime();
    }

}
